package com.lemon.springcloud.core.bean;

import com.lemon.core.common.lang.util.SystemEnvUtils;

import java.lang.management.ManagementFactory;

/**
 * Class Name: AppRegister
 * Create Date: 18-3-15 下午1:21
 * Creator: lemon
 * Version: v1.0
 * Updater:
 * Date Time:
 * Description:
 */
public class ServiceInfo {

    private static Long startTime;

    private static Long endTime;
    /**
     * 启动耗时
     */
    private static Long starterDuration;

    private static String javaRuntime;
    private static String applicationName;
    private static String serverPort;

    // 是否注册了服务停止监听器
    private Boolean shutdownListenerRegistered = false;
    // 是否注册了服务告警
    private Boolean registerNotificationHook = false;

    private static String devHost;
    private static String devDesc;

    private static String serviceTag;
    /**
     * 当前服务id
     */
    private static String serviceUUID;
    private static String serviceRouteTag = "default";
    private static String serviceWeight = "1";
    private static Integer pid;
    private String eurekaZone;
    private static String env;
    private static String ip;

    public static String ENV_NAME = SystemEnvUtils.IS_PROD ? "prod" : "test";

    static {
        serviceTag = System.getProperty("lemon.springcloud.tag", "A");
        String name = ManagementFactory.getRuntimeMXBean().getName();
        pid = Integer.valueOf(name.split("@")[0]);
        String sysEnv = System.getenv("MOP_ENV_NAME");
        String defaultEnv = sysEnv == null || !sysEnv.equalsIgnoreCase("PROD") ? "TEST" : "PROD";
        env = System.getProperty("mop.env.name", defaultEnv);
        ip = "unknown";
    }

    public void setStartTime(Long startTime) {
        ServiceInfo.startTime = startTime;
    }

    public Long getStartTime() {
        return startTime;
    }

    public Long getEndTime() {
        return endTime;
    }

    public void setEndTime(Long endTime) {
        this.endTime = endTime;
    }

    public Boolean getShutdownListenerRegistered() {
        return shutdownListenerRegistered;
    }

    public void setShutdownListenerRegistered(Boolean shutdownListenerRegistered) {
        this.shutdownListenerRegistered = shutdownListenerRegistered;
    }

    public Boolean getRegisterNotificationHook() {
        return registerNotificationHook;
    }

    public void setRegisterNotificationHook(Boolean registerNotificationHook) {
        this.registerNotificationHook = registerNotificationHook;
    }

    public String getServiceTag() {
        return serviceTag;
    }

    public void setServiceTag(String serviceTag) {
        ServiceInfo.serviceTag = serviceTag;
    }

    public static Integer getPid() {
        return pid;
    }

    public void setPid(Integer pid) {
        ServiceInfo.pid = pid;
    }

    public String getJavaRuntime() {
        return javaRuntime;
    }

    public void setJavaRuntime(String javaRuntime) {
        this.javaRuntime = javaRuntime;
    }

    public Long getStarterDuration() {
        return starterDuration;
    }

    public void setStarterDuration(Long starterDuration) {
        this.starterDuration = starterDuration;
    }

    public static void setApplicationName(String applicationName) {
        ServiceInfo.applicationName = applicationName;
    }

    public static String getApplicationName() {
        return applicationName;
    }

    public void setServerPort(String serverPort) {
        this.serverPort = serverPort;
    }

    public static String getServerPort() {
        return serverPort;
    }

    public void setEurekaZone(String eurekaZone) {
        this.eurekaZone = eurekaZone;
    }

    public String getEurekaZone() {
        return eurekaZone;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public static String getIp() {
        return ip;
    }

    public static String getEnv() {
        return env;
    }

    public void setEnv(String env) {
        ServiceInfo.env = env;
    }

    public static String getServiceUUID() {
        return serviceUUID;
    }

    public static void setServiceUUID(String serviceUUID) {
        ServiceInfo.serviceUUID = serviceUUID;
    }

    public static String getServiceRouteTag() {
        return serviceRouteTag;
    }

    public static void setServiceRouteTag(String serviceRouteTag) {
        ServiceInfo.serviceRouteTag = serviceRouteTag;
    }

    public static String getServiceWeight() {
        return serviceWeight;
    }

    public static void setServiceWeight(String serviceWeight) {
        ServiceInfo.serviceWeight = serviceWeight;
    }

    public String getDevHost() {
        return ServiceInfo.devHost;
    }

    public static void setDevHost(String devHost) {
        ServiceInfo.devHost = devHost;
    }

    public String getDevDesc() {
        return devDesc;
    }

    public static void setDevDesc(String devDesc) {
        ServiceInfo.devDesc = devDesc;
    }
}
